<?php

$userid = get_loggedin_userid();
$client_id = get_input('client_id');
$json_facebook_ids = get_input('Facebook_ids');
$brief = get_input('brief');

if ($json_facebook_ids) {
    $facebook_ids = json_decode($json_facebook_ids, true);
}

$users = array();

foreach($facebook_ids as $facebook_id) {
    $facebookAccounts = greengar_get_facebook($facebook_id, NULL);
    if($facebookAccounts && $facebookAccounts[0]) {
        $facebookAccount = $facebookAccounts[0];
        $friendid = $facebookAccount->owner_guid;
        $friendEntity = get_user($friendid);
        $users[] = userToArray($friendEntity, $client_id, $brief);
    }
}

echo json_encode(export_result(200, $users));
?>